﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class PollDaddyTests
{
    [TestMethod]
    public void ShouldGetUserCode()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");
        
        var userCode = Polldaddy.GetUserCode();

        Assert.IsNotNull(userCode);
    }

    [TestMethod]
    public void ShouldGetPoll()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var poll = Polldaddy.GetPoll("4113128");

        Assert.IsNotNull(poll);
        Assert.AreEqual("4113128", poll.id);
    }

    [TestMethod]
    public void ShouldGetPollResults()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var results = Polldaddy.GetPollResults("4113128");

        Assert.IsNotNull(results);
        Assert.IsTrue(results.Count() > 0);
    }
    
    [TestMethod]
    public void ShouldGetPollComments()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var pollComments = Polldaddy.GetPollComments("4113128");
        Assert.IsNotNull(pollComments);
        Assert.IsTrue(pollComments.Count() > 0);
    }

    [TestMethod]
    [ExpectedException(typeof(InvalidOperationException))]
    public void ShouldGetPollCommentsThrowExceptionIfPollIsInvalid()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var comments = Polldaddy.GetPollComments("invalid-poll-id");
    }

    [TestMethod]
    [ExpectedException(typeof(InvalidOperationException))]
    public void ShouldGetPollResultsThrowExceptionIfPollIsInvalid()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var pollResults = Polldaddy.GetPollResults("invalid-poll-id");
    }

    [TestMethod]
    [ExpectedException(typeof(InvalidOperationException))]
    public void ShouldGetPollThrowExceptionIfPollIsInvalid()
    {
        Polldaddy.Initialize("65dcb2e1-2052-19c8-cb63-000031d1a612");

        var poll = Polldaddy.GetPoll("invalid-poll-id");
    }
}
